package org.example.app.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 店铺排行榜结果实体类 - 符合实时数仓设计规范
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ShopRankResult extends BaseDwsBean {
    
    // 业务主键
    private String shopId;
    private String shopName;
    
    // 地理维度
    private String cityId;
    private String cityName;
    private String provinceId;
    private String provinceName;
    
    // 店铺基本信息
    private String shopType;
    private String shopLevel;
    private String openTime;
    
    // 度量字段
    private Double totalSalesAmount;
    private Long totalSalesCount;
    private Double avgOrderValue;
    private Double currentSales;
    private Double previousSales;
    private Double growthRate;
    private Long visitorCount;
    private Double conversionRate;
    private Long productCount;     // 商品数量
    private Double customerRating; // 客户评分
    
    // 市场份额分析
    private Double marketShare;
    private Double cityShare;
    
    /**
     * 计算增长率
     */
    public void calculateGrowthRate() {
        if (previousSales != null && previousSales > 0 && currentSales != null) {
            this.growthRate = (currentSales - previousSales) / previousSales * 100;
        } else {
            this.growthRate = 0.0;
        }
    }
    
    /**
     * 计算平均订单价值
     */
    public void calculateAvgOrderValue() {
        if (totalSalesCount != null && totalSalesCount > 0 && totalSalesAmount != null) {
            this.avgOrderValue = totalSalesAmount / totalSalesCount;
        } else {
            this.avgOrderValue = 0.0;
        }
    }
    
    /**
     * 设置销售数据
     */
    public void setSalesData(Double current, Double previous) {
        this.currentSales = current;
        this.previousSales = previous;
        calculateGrowthRate();
    }
}